package com.superpai.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RelativeLayout;

import com.superpai.R;
import com.superpai.utils.AndroidUtils;

/**
 * @author Devin.Hu
 * @date 2011-8-13
 * @version V1.0
 * @description 首页
 */
public class HomeActivity extends BaseActivity {

	private RelativeLayout home_promotion_layout;
	private RelativeLayout home_category_layout;
	private RelativeLayout home_convenience_layout;
	private RelativeLayout home_koubei_layout;
	private RelativeLayout home_shop_layout;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		initMenuView(this, mIndexHome);
		initViews();
	}
	
	/** 初始化页面  **/
	private void initViews(){
		
		home_promotion_layout = (RelativeLayout)this.findViewById(R.id.home_promotion_layout);
		home_category_layout = (RelativeLayout)this.findViewById(R.id.home_category_layout);
		home_convenience_layout = (RelativeLayout)this.findViewById(R.id.home_convenience_layout);
		home_koubei_layout = (RelativeLayout)this.findViewById(R.id.home_koubei_layout);
		home_shop_layout = (RelativeLayout)this.findViewById(R.id.home_shop_layout);
		
		home_promotion_layout.setOnClickListener(this);
		home_category_layout.setOnClickListener(this);
		home_convenience_layout.setOnClickListener(this);
		home_koubei_layout.setOnClickListener(this);
		home_shop_layout.setOnClickListener(this);
	}


	
	
	@Override
	public Object doDataConnection(int type) {
		
		return null;
	}

	@Override
	public void doProcessData(int type, Object... values) 
	{
		
	}


	@Override
	public void onClick(View v) {
		
		checkMenu(v);
		
		if(v == home_promotion_layout){
			AndroidUtils.Toast(mContext, mContext.getString(R.string.common_nosupport));
//			Intent intent = this.getIntent();
//			intent.setClass(mContext, PromotionActivity.class);
//			mContext.startActivity(intent);
		}
		if(v == home_category_layout){
			Intent intent = this.getIntent();
			intent.setClass(mContext, CategoryActivity.class);
			mContext.startActivity(intent);
		}
		if(v == home_convenience_layout){
			AndroidUtils.Toast(mContext, mContext.getString(R.string.common_nosupport));
//			Intent intent = this.getIntent();
//			intent.setClass(mContext, ConvenienceActivity.class);
//			mContext.startActivity(intent);
		}
		if(v == home_koubei_layout){
			AndroidUtils.Toast(mContext, mContext.getString(R.string.common_nosupport));
		}
		if(v == home_shop_layout){
			Intent intent = this.getIntent();
			intent.setClass(mContext, AboutActivity.class);
			mContext.startActivity(intent);
		}
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			new AlertDialog.Builder(this)
			.setTitle(R.string.common_tishi)
			.setMessage(R.string.common_sys_exit)
			.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					sysExit();
				}
			})
			.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {

				}
			})
			.show();
			return true;
		}else{
			return super.onKeyDown(keyCode, event);
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		disConnection();
	}
}